package com.cy.controller;

import com.cy.domain.Goods;
import com.cy.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @RequestMapping("/findAll")
    public String findAll(Model model){
        model.addAttribute("list",goodsService.findAll());
        return "Goods-Index";
    }

    @RequestMapping("/deleteById/{id}")
    public String deleteById(@PathVariable Integer id){
        goodsService.deleteById(id);
        return "forward:/goods/findAll";
    }

    @RequestMapping("/goodsInsertOutput")
    public String goodsInsertOutput(){
        return "Goods-Insert";
    }

    @RequestMapping("/goodsInsertInput")
    public String goodsInsertInput(Goods goods){
        goodsService.goodsInsert(goods);
        return "forward:/goods/findAll";
    }

    @RequestMapping("/goodsSelectOne/{id}")
    public String goodsSelectOne(@PathVariable Integer id,Model model){
        model.addAttribute("goods",goodsService.selectOne(id));
        return "Goods-Update";
    }

    @RequestMapping("/goodsUpdateInput")
    public String goodsUpdateInput(Goods goods){
        goodsService.goodsUpdate(goods);
        return "forward:/goods/findAll";
    }

}
